/*
 * Powered By XY
 * Since 2020
 */

package com.xy.biz.fd.controller;

import java.util.Collection;
import java.util.List;

import com.xy.biz.fd.dao.DocumentRelationDao;
import com.xy.biz.fd.domain.bo.DocumentBO;
import com.xy.biz.fd.domain.po.DocumentRelationPO;
import com.xy.biz.fd.domain.req.relation.GetDocumentRelationRequest;
import com.xy.biz.fd.domain.req.relation.ListDocumentRelationRequest;
import com.xy.biz.fd.domain.req.relation.SaveDocumentRelationRequest;
import com.xy.biz.fd.domain.resp.GetDocRelationResponse;
import com.xy.biz.fd.domain.resp.GetDocumentResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.xy.lang.domain.Page;
import com.xy.lang.domain.Result;
import com.xy.lang.validation.SaveChecks;
import com.xy.lang.validation.UpdateChecks;
import com.xy.lang.validation.annotation.Validatable;

import com.xy.biz.fd.domain.resp.GetDocumentRelationResponse;
import com.xy.biz.fd.domain.query.DocumentRelationQuery;
import com.xy.biz.fd.domain.converter.DocumentRelationConverter;
import com.xy.biz.fd.client.DocumentRelationClient;
import com.xy.biz.fd.service.DocumentRelationService;

/**
 *
 *
 * @author wcs
 * @date 2021-2-5
 */
@Api(tags = "文档关联关系")
@Slf4j
@RestController
@RequestMapping("/api/fd/document_relation")
public class DocumentRelationController implements DocumentRelationClient {

	@Autowired
	private DocumentRelationService documentRelationService;

	@Validatable(groups = {SaveChecks.class})
	@PostMapping(value = "/save")
	public Result<?> saveDocumentRelation(@RequestBody GetDocumentRelationRequest request) {
		return documentRelationService.saveDocumentRelation(request);
	}

	/*@Validatable(groups = {UpdateChecks.class})
	@PostMapping(value = "/update")
	public Result<?> updateDocumentRelation(@RequestBody SaveDocumentRelationRequest request) {
		documentRelationService.updateDocumentRelation(DocumentRelationConverter.toBO(request));
		return Result.success();
	}*/

	@Validatable
	@PostMapping(value = "/delete")
	public Result<?> deleteDocumentRelation(@RequestBody GetDocumentRelationRequest request) {
		documentRelationService.deleteDocumentRelation(request);
		return Result.success();
	}

	/*@Validatable
	@PostMapping(value = "/get")
	@Override
	public Result<GetDocumentRelationResponse> getDocumentRelation(@RequestBody GetDocumentRelationRequest request) {
		return Result.success(DocumentRelationConverter.toResponse(documentRelationService.getDocumentRelation(request.getDocumentRelationId())));
	}

	@PostMapping(value = "/list_by_ids")
	@Override
	public Result<List<GetDocumentRelationResponse>> listDocumentRelationById(@RequestBody Collection<Long> collection) {
		return Result.success(DocumentRelationConverter.toResponse(documentRelationService.listDocumentRelationById(collection)));
	}

	@PostMapping(value = "/list")
	@Override
	public Result<List<GetDocumentRelationResponse>> listDocumentRelation(@RequestBody ListDocumentRelationRequest request) {
		return Result.success(DocumentRelationConverter.toResponse(documentRelationService.listDocumentRelation(DocumentRelationConverter.toQuery(request))));
	}

	@PostMapping(value = "/count")
	@Override
	public Result<Integer> countDocumentRelation(@RequestBody ListDocumentRelationRequest request) {
		return Result.success(documentRelationService.countDocumentRelation(DocumentRelationConverter.toQuery(request)));
	}

	@PostMapping(value = "/page")
	@Override
	public Result<Page<GetDocumentRelationResponse>> pageDocumentRelation(@RequestBody ListDocumentRelationRequest request) {
		DocumentRelationQuery query = DocumentRelationConverter.toQuery(request);
		List<GetDocumentRelationResponse> list = DocumentRelationConverter.toResponse(documentRelationService.listDocumentRelation(query));
		int count = documentRelationService.countDocumentRelation(query);
		return Result.success(new Page<>(list, count));
	}*/

	/*@PostMapping(value = "/page")
	public Result<?> pageDocumentRelation(@RequestBody ListDocumentRelationRequest request) {
		DocumentRelationQuery query = DocumentRelationConverter.toQueryMax(request);
		return documentRelationService.listDocumentRelation(query);
	}*/

	@ApiOperation(value = "获取文档全部关联信息")
	@PostMapping(value = "/page")
	public Result<List<GetDocRelationResponse>> pageDocumentRelation(@RequestBody ListDocumentRelationRequest request) {
		DocumentRelationQuery query = DocumentRelationConverter.toQueryMax(request);
		return Result.success(documentRelationService.listDocumentRelation(query));
	}

}
